import http from "@/utils/http";
import { getToken, getUid } from "@/utils/token";

//
export function cartAddAPI(userid, proid, num = 1) {
  let token = getToken();
  return http({
    method: "POST",
    url: "/api/cart/add",
    data: {
      userid,
      proid,
      num,
    },
    headers: {
      token: token,
    },
  });
}

export function cartListAPI() {
  let userid = getUid();
  let token = getToken();
  return http({
    method: "POST",
    url: "/api/cart/list",
    data: {
      userid,
    },
    headers: {
      token: token,
    },
  });
}

export function cartDelAPI(cartid) {
  // let userid = getUid();
  let token = getToken();
  return http({
    method: "POST",
    url: "/api/cart/remove",
    data: {
      // userid,
      cartid,
    },
    headers: {
      token: token,
    },
  });
}

export function cartUpdateNumAPI(cartid, num) {
  // let userid = getUid();
  // let token = getToken();
  return http({
    method: "POST",
    url: "/api/cart/updatenum",
    data: {
      // userid,
      cartid,
      num,
    },
    // headers: {
    //   token: token,
    // },
  });
}

export function cartSingleSelectedAPI(cartid, flag) {
  // let userid = getUid();
  let token = getToken();
  return http({
    method: "POST",
    url: "/api/cart/selectone",
    data: {
      // userid,
      cartid,
      flag,
    },
    headers: {
      token: token,
    },
  });
}

export function cartAllSelectedAPI(flag) {
  let userid = getUid();
  let token = getToken();
  return http({
    method: "POST",
    url: "/api/cart/selectall",
    data: {
      // userid,
      userid,
      // type 参数名要跟接口文档一致
      type: flag,
    },
    headers: {
      token: token,
    },
  });
}
